package com.blog.blog.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.blog.blog.dao.pojo.Tag;
import com.blog.blog.service.TagService;
import com.blog.blog.vo.Result;
import com.blog.blog.vo.WebResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("tags")
public class TagsController {
    @Autowired
    TagService tagsService;

    @GetMapping("/hot")
    public Result hot() {
        int limit = 6;
        return tagsService.hots(limit);
    }

    @GetMapping
    public Result findAll() {
        return tagsService.findAll();
    }

    @GetMapping("detail")
    public Result findAllDetail(){
        return tagsService.findAllDetail();
    }

    @GetMapping("detail/{id}")
    public Result findDetailById(@PathVariable("id") Long id) {
        return tagsService.findDetailById(id);
    }

    @GetMapping("findPersonalTag")
    public WebResult<List<JSONObject>> findPersonalTag() {
        return WebResult.<List<JSONObject>>builder()
                .code(200)
                .message(WebResult.REQUEST_STATUS_SUCCESS)
                .data(tagsService.findPersonalTag())
                .build();
    }

}
